package com.csgc.camera.biz.other.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.csgc.camera.base.BaseBindingActivity
import com.csgc.camera.biz.MainActivity
import com.csgc.camera.biz.other.adapter.GuidePageAdapter

import com.csgc.camera.storage.CommonPreference
import com.csgc.camera.util.clickWithTrigger
import com.cysd.spsyxj.databinding.ActivityGuideBinding

import com.gyf.immersionbar.ktx.immersionBar

class GuideActivity:BaseBindingActivity<ActivityGuideBinding>(ActivityGuideBinding::inflate) {

    companion object{
        fun launch(context: Context){
            context.startActivity(Intent(context,GuideActivity::class.java))
        }
    }
    private val adapter:GuidePageAdapter by lazy {
       val adapter =  GuidePageAdapter(this)
        adapter.listener = object :GuidePageAdapter.OnNextListener{
            override fun onNext(position: Int) {
                if (position<2){
                    binding.vpGuidePage.setCurrentItem(binding.vpGuidePage.currentItem+1,true)
                }else{
                    val chooseMask = CommonPreference.instance.isShowChooseMask()
                    if(chooseMask){
                        MainActivity.launch(this@GuideActivity)
                    }else{
                        ChooseMaskStyleActivity.launch(this@GuideActivity)
                    }
                    finish()
                }
            }
        }
        adapter
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        immersionBar {
            transparentStatusBar()
            fitsSystemWindows(false)
            statusBarDarkFont(true)
            transparentNavigationBar()
        }
        CommonPreference.instance.setGuidePage(true)

        binding.vpGuidePage.offscreenPageLimit = 3
        binding.vpGuidePage.adapter = adapter

        binding.tvJumpMain.clickWithTrigger {
            val chooseMask = CommonPreference.instance.isShowChooseMask()
            if(chooseMask){
                MainActivity.launch(this@GuideActivity)
            }else{
                ChooseMaskStyleActivity.launch(this)
            }

            finish()
        }


    }

}